import React, {Component} from 'react';
import AlibcaMgr from '../sdkManager/alibabaManager';
import {
  StyleSheet,
  SafeAreaView,
  Text,
  TouchableOpacity,
  NativeModules,
    ScrollView
} from 'react-native';

// const CalendarManager = NativeModules.CalendarManager;

export default class TestComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      text: '测试',
      isLogin: '没登录',
      userInfo: '用户数据',

      Pid: 'mm_169220122_1290100019_110104050415', //三段式
      Adzoneid: '110104050415', //pid三段式最后一段
      taokeAppkey: '29182154', //'28617401', //阿里妈妈那边网站或者app的appkey

      OpenType: 'Auto', //打开的方式
      clientType: 'taobao', //taobao---唤起淘宝客户端；tmall---唤起天猫客户端
      BACK_URL: 'alisdk://', //唤端返回的scheme
      AlibcFailModeType: 'AlibcNativeFailModeJumpH5', //（唤端失败模式）
      isvcode: 'app', //必须传
    };
  }



  render() {
    return (
      <SafeAreaView>
          <ScrollView>
              <Text>===================================测试===================</Text>
              <Text style={style.container}>{this.state.text}</Text>
              <TouchableOpacity
                  onPress={() => {
                      // CalendarManager.addEvent(
                      //   'Birthday Party',
                      //   '4 Privet Drive, Surrey',
                      // );
                      // AlibcaMgr.show('点击了', 2, msg => {
                      //   this.setState({
                      //     text: msg,
                      //   });
                      // });
                  }}>
                  <Text style={style.container}>测试</Text>
              </TouchableOpacity>
              <Text>
                  ===================================初始化===================
              </Text>
              <TouchableOpacity
                  onPress={() => {
                      AlibcaMgr.asyncInit((code, map) => {
                          this.setState({
                              text: map.code,
                          });
                      });
                  }}>
                  <Text style={style.container}>初始化 asyncInit</Text>
              </TouchableOpacity>
              <Text>===================================登录===================</Text>
              <TouchableOpacity
                  onPress={() => {
                      AlibcaMgr.showLogin((code, param) => {
                          this.setState({
                              text: code,
                              isLogin: code == 0 ? '已经登录' : '没登录',
                          });
                      });
                  }}>
                  <Text style={style.container}>{this.state.isLogin}</Text>
              </TouchableOpacity>
              <Text>
                  ===================================是否已经登录===================
              </Text>
              <TouchableOpacity
                  onPress={() => {
                      AlibcaMgr.isLogin((code, param) => {
                          this.setState({
                              text: code,
                              isLogin: code == 0 ? '已经登录' : '没登录',
                          });
                      });
                  }}>
                  <Text style={style.container}>{this.state.isLogin}</Text>
              </TouchableOpacity>
              <Text>
                  ===================================获取用户信息===================
              </Text>
              <TouchableOpacity
                  onPress={() => {
                      AlibcaMgr.getUserInfo((code, param) => {
                          this.setState({
                              text: code,
                              userInfo:
                                  code == 0
                                      ? param.nick + ',' + param.avatarUrl + ',' + param.openId
                                      : '登录失败!',
                          });
                      });
                  }}>
                  <Text style={style.container}>{this.state.userInfo}</Text>
              </TouchableOpacity>
              <Text>
                  ===================================退出登录===================
              </Text>
              <TouchableOpacity
                  onPress={() => {
                      AlibcaMgr.logout((code, param) => {
                          this.setState({
                              text: code,
                              isLogin: code == 0 ? '已退出登录' : '已经登录',
                          });
                      });
                  }}>
                  <Text style={style.container}>退出登录</Text>
              </TouchableOpacity>
              <Text>===============================show=======================</Text>
              <TouchableOpacity
                  onPress={() => {
                      //详情页
                      var parm = {
                          //详情  （和 url 一样）
                          //  itemid: "612996128437",
                          //  BizCodeStr:"detail",  //detal  shop

                          // 商店
                          // shopid:"123367260",
                          // BizCodeStr:"shop",  //detal  shop
                          // sellerId:"123367260",      //使用shop方式就需要填写这个sellerId

                          //购物车
                          //BizCodeStr:"cart",  //detal  shop  cart(购物车)

                          // url : "https://s.click.taobao.com/gkuRPnv"   //劵地址
                          //  url:"https://s.click.taobao.com/NksRPnv"     //购买地址一样

                          url: 'https://s.click.taobao.com/PMQ8lzu',
                      };
                      var params = this.mkParam(parm);
                      // AlibcaMgr.addEvent(
                      //     {
                      //         type: 'url', //detail shop mycard url
                      //         payload: params,
                      //       }
                      //     , "2222");
                      AlibcaMgr.showPage(
                          {
                              type: 'url', //detail shop mycard url
                              payload: params,
                          },
                          (code, info) => {
                              this.setState({
                                  text: code,
                              });
                          },
                      );
                  }}>
                  <Text style={style.container}>显示</Text>
              </TouchableOpacity>
          </ScrollView>

      </SafeAreaView>
    );
  }
}

const style = StyleSheet.create({
  container: {
    color: 'blue',
    fontSize: 30,
  },
});
